
# Paypal wranging

# THE STEPS:
# Download the transaction history as a csv file from Paypal
# Put the file into the psd directory
# Run this script

M = read.csv( "Download.csv", stringsAsFactors=FALSE )
M = M[ c("Item.Title", "Gross","Fee","Net","From.Email.Address","Date") ]
head(M)
M = subset( M, Gross > 0 )

M$personID = gsub( "^.*\\((.*)\\)", '\\1', M$Item.Title, perl=TRUE )
M = M[-c(1)]
M$Date = as.Date( M$Date, "%m/%d/%Y" ) 

M = M[order(M$Date),]


head(M)
nrow(M)
cat( "Gross = ", sum(M$Gross), "\nFee = ", sum(M$Fee), "\nNet = ", sum(M$Net), "\nFolks = ", sum(M$Gross) / 12, "\n" )


M$Net = NULL
M$Fee = NULL

bl = read.csv( "banList.csv", stringsAsFactors=FALSE )
#bl = banL[1:2]
#bl = bl[ 1:6 ]
bl$Gross = NULL
bl$From.Email.Address = NULL
bl$Date = NULL

MM = merge( bl, M, all=TRUE)
#MM


MM$Paid[!is.na(MM$Gross)] = "y"
cat( "Weird - not on ban list\n" )
print( MM[is.na(MM$pubname),] )

cat( "New ban list saved\n" )
MM = MM[!is.na(MM$pubname),]
#print( MM[1:7] )

# MM[ -c(3) ]
#bl$In = ""

write.csv( MM, file="banList.csv", quote=FALSE, row.names=FALSE)


#print( MM[ !is.na(MM$Paid) & MM$Paid == "y" & MM$In!="y", -c(3) ] )



skip = function() {


source( "polyDataRead.R" )
# folks who are in various categories
#P = read.csv( "allFolks.csv", stringsAsFactors=FALSE );
P = read.csv( "allFolks.csv", stringsAsFactors=FALSE );
rownames(P) = P$personID

ban = read.csv( "banList.csv", stringsAsFactors=FALSE )
ban = ban[c(1,4,5,6)]
	
 
P = merge( P, ban, by="personID", all=TRUE )
save.file(P, collapse.groups=TRUE, file="allRegistered.csv", 
				orderBy=c( "Paid","gender1", "lookGender1") )

cat( "allRegistered has full list of registered folks\n" )
				
#P = read.csv( "allRegistered.csv", stringsAsFactors=FALSE );
  
# print( P[ P$Paid == "", ] )
  
}

